package com.eastfair.home.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.eastfair.annotation.annotation.log.SysLog;
import com.eastfair.boot.request.PageParams;
import com.eastfair.core.base.R;
import com.eastfair.core.exception.BizException;
import com.eastfair.home.service.HomeServiceLossService;
import com.eastfair.venueservice.dto.ServiceLossDTO;
import com.eastfair.venueservice.vo.ServiceLossVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;

/**
 * 服务报损 REST API.
 *
 * @author dqq
 * @date 2022 /9/22
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/serviceLoss")
@Api(value = "ServiceLoss", tags = "报损记录")
public class ServiceLossController {

    @Resource
    private HomeServiceLossService homeServiceLossService;

    /**
     * 分页查询报损记录VO列表.
     *
     * @param pageParams the page params
     * @return the r
     */
    @ApiOperation("分页查询报损记录VO列表")
    @PostMapping("/query/serviceLoss")
    public R<Page<ServiceLossVO>> queryServiceLoss(@RequestBody PageParams<ServiceLossDTO> pageParams) {
        log.info("queryServiceLoss - 分页查询报损记录VO列表, pageParams={}", pageParams);
        return R.successDef(homeServiceLossService.queryServiceLoss(pageParams));
    }

    /**
     * 返修入库.
     *
     * @param serviceLossDTO the service loss dto
     * @return the r
     */
    @ApiOperation("返修入库")
    @SysLog("返修入库")
    @PostMapping("/repair/inInventory")
    public R<Boolean> repairInInventory(@RequestBody ServiceLossDTO serviceLossDTO) {
        log.info("repairInInventory - 返修入库, serviceLossDTO={}", serviceLossDTO);
        return R.successDef(homeServiceLossService.repairInInventory(serviceLossDTO));
    }


    /**
     * 报损类型统计.
     *
     * @param serviceLossDTO the service loss dto
     * @return the r
     */
    @ApiOperation("报损类型统计")
    @PostMapping("/count/lossNum")
    public R<Map<String, Object>> countLossNum(@RequestBody ServiceLossDTO serviceLossDTO) {
        log.info("countLossNum - 报损类型统计, serviceLossDTO={}", serviceLossDTO);
            Map<String, Object> map = homeServiceLossService.countLossNum(serviceLossDTO);
            return R.successDef(map);
    }
}